<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head><meta name="generator" content="Hexo 3.8.0">

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->

    

    
        <meta name="description" content="一、编译openssl最简单的方法，github上找一个脚本，如：https://github.com/gitusrs/openssl-ios-build-shell-script 下载openssl源码，根据版本，改一下脚本的 OPENSSL_COMPRESSED_FN=”openssl-1.0.">
    

    <!--Author-->
    
        <meta name="author" content="Cyrus">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="iOS 集成ONVIF客户端">
    

    <!--Open Graph Description-->
    
        <meta property="og:description" content="一、编译openssl最简单的方法，github上找一个脚本，如：https://github.com/gitusrs/openssl-ios-build-shell-script 下载openssl源码，根据版本，改一下脚本的 OPENSSL_COMPRESSED_FN=”openssl-1.0.">
    

    <!--Open Graph Site Name-->
        <meta property="og:site_name" content="Cyrus的技术空间">

    <!--Type page-->
    
        <meta property="og:type" content="article">
    

    <!--Page Cover-->
    
    
        <meta property="og:image" content="http://cyrus_huang.gitee.io/bloghttp://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg">
    

        <meta name="twitter:card" content="summary_large_image">

    

    
        <meta name="twitter:image" content="http://cyrus_huang.gitee.io/bloghttp://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg">
    

    <!-- Title -->
    
    <title>iOS 集成ONVIF客户端 - Cyrus的技术空间</title>

    <!-- Bootstrap Core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/blog/css/style.css">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet">

    <!-- Google Analytics -->
    


    <!-- favicon -->
    

</head>


<body>

    <!-- Menu -->
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/blog/">Cyrus的技术空间</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                
                    <li>
                        <a href="/blog/">
                            
                                Home
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/archives">
                            
                                Archives
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/tags">
                            
                                Tags
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/categories">
                            
                                Categories
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="https://github.com/klugjo/hexo-theme-clean-blog">
                            
                                <i class="fa fa-github fa-stack-2x"></i>
                            
                        </a>
                    </li>
                
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <!-- Main Content -->
    <!-- Page Header -->
<!-- Set your background image for this header in your post front-matter: cover -->

<header class="intro-header" style="background-image: url('http://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>iOS 集成ONVIF客户端</h1>
                    
                    <span class="meta">
                        <!-- Date and Author -->
                        
                            Posted by Cyrus on
                        
                        
                            2020-01-16
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Tags and categories -->
           
                <div class="col-lg-4 col-lg-offset-2 col-md-5 col-md-offset-1 post-tags">
                    
                        


<a href="/blog/tags/ONVIF/">#ONVIF</a>


                    
                </div>
                <div class="col-lg-4 col-md-5 post-categories">
                    
                </div>
            

            <!-- Gallery -->
            

            <!-- Post Main Content -->
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <h3 id="一、编译openssl"><a href="#一、编译openssl" class="headerlink" title="一、编译openssl"></a>一、编译openssl</h3><p>最简单的方法，github上找一个脚本，如：<a href="https://github.com/gitusrs/openssl-ios-build-shell-script" target="_blank" rel="noopener">https://github.com/gitusrs/openssl-ios-build-shell-script</a> 下载openssl源码，根据版本，改一下脚本的<strong> OPENSSL_COMPRESSED_FN=”openssl-1.0.2e.tar.gz” </strong> 与源码版本相对应，运行一下，就ok了。</p>
<h3 id="二、创建OC项目"><a href="#二、创建OC项目" class="headerlink" title="二、创建OC项目"></a>二、创建OC项目</h3><p>1、将上篇文章生成的 onvif c语言文件及封装的OnvifDevice和OnvifControl 文件复制到项目中，将上面编译成的openssl静态库，设置一下头文件和静态库的路径，如下图：<br><img src="http://cyrus_huang.gitee.io/blog/2020/01/16/iOS-集成ONVIF客户端/onvif_oc_1.png" alt=""></p>
<h4 id="1、搜索设备"><a href="#1、搜索设备" class="headerlink" title="1、搜索设备"></a>1、搜索设备</h4><p>搜索设备，把设备地址放到数组并展示到列表中：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">- (IBAction)searchDeviceAction:(id)sender &#123;</span><br><span class="line">    ONVIF_DetectDevice(cb_discovery, (__bridge void *)self);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">void cb_discovery(void *userinfo, struct wsdd__ProbeMatchesType *wsdd__ProbeMatches)</span><br><span class="line">&#123;</span><br><span class="line">    if (NULL == wsdd__ProbeMatches) &#123;</span><br><span class="line">        return;</span><br><span class="line">    &#125;</span><br><span class="line">    ViewController *vc = (__bridge ViewController *)(userinfo);</span><br><span class="line">    [vc gotDeviceAddrs:wsdd__ProbeMatches];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)gotDeviceAddrs:(struct wsdd__ProbeMatchesType *)wsdd__ProbeMatches</span><br><span class="line">&#123;</span><br><span class="line">    for(int i = 0; i &lt; wsdd__ProbeMatches-&gt;__sizeProbeMatch; i++) &#123;</span><br><span class="line">        struct wsdd__ProbeMatchType *probeMatch = wsdd__ProbeMatches-&gt;ProbeMatch + i;</span><br><span class="line">        printf(&quot;%s\n&quot;, probeMatch-&gt;XAddrs);</span><br><span class="line">        [_addrs addObject:[NSString stringWithUTF8String:probeMatch-&gt;XAddrs]];</span><br><span class="line">    &#125;</span><br><span class="line">    [self.tableView reloadData];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><img src="http://cyrus_huang.gitee.io/blog/2020/01/16/iOS-集成ONVIF客户端/onvif_oc_2.png" alt=""></p>
<h4 id="2、连接设备并进行相关操作"><a href="#2、连接设备并进行相关操作" class="headerlink" title="2、连接设备并进行相关操作"></a>2、连接设备并进行相关操作</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">- (IBAction)connectButtonAction:(id)sender &#123;</span><br><span class="line">    _device = createDevice(_addr.UTF8String, _nameTf.text.UTF8String, _passwdTf.text.UTF8String);</span><br><span class="line">    </span><br><span class="line">    int result = ONVIF_GetCapabilities(_device);</span><br><span class="line">    if (result != SOAP_OK) &#123;</span><br><span class="line">        NSLog(@&quot;ONVIF_GetCapabilities fail&quot;);</span><br><span class="line">        return;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    result = ONVIF_GetProfile(_device);</span><br><span class="line">    if (result != SOAP_OK) &#123;</span><br><span class="line">        NSLog(@&quot;ONVIF_GetProfile fail&quot;);</span><br><span class="line">        return;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    // 播放，简单起见，直接用vlc</span><br><span class="line">    VLCViewController *vlcVC = [[VLCViewController alloc] init];</span><br><span class="line">    vlcVC.device = self.device;</span><br><span class="line">    [self.navigationController pushViewController:vlcVC animated:YES];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="http://cyrus_huang.gitee.io/blog/2020/01/16/iOS-集成ONVIF客户端/onvif_oc_3.png" alt=""><br><img src="http://cyrus_huang.gitee.io/blog/2020/01/16/iOS-集成ONVIF客户端/onvif_oc_4.png" alt=""></p>
<h4 id="3、播放"><a href="#3、播放" class="headerlink" title="3、播放"></a>3、播放</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    // Do any additional setup after loading the view from its nib.</span><br><span class="line">    </span><br><span class="line">    _player = [[VLCMediaPlayer alloc] init];</span><br><span class="line">    _player.drawable = self.playView;</span><br><span class="line">    </span><br><span class="line">    [self queryStreamURI];</span><br><span class="line">    </span><br><span class="line">    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(infoButtonAction:)];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)queryStreamURI</span><br><span class="line">&#123;</span><br><span class="line">	// ipc 有两个profile，对应不同分辨率的配置，这里用按钮是否选中区别分辨率</span><br><span class="line">    char uri[128] = &#123;0&#125;;</span><br><span class="line">    ONVIF_GetStreamUri(_device, _uriButton.selected, uri, sizeof(uri));</span><br><span class="line">    [self playWithURI:[NSString stringWithUTF8String:uri]];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)playWithURI:(NSString *)uri</span><br><span class="line">&#123;</span><br><span class="line">    if (_player.playing) &#123;</span><br><span class="line">        [_player stop];</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    VLCMedia *media = [[VLCMedia alloc] initWithURL:[NSURL URLWithString:uri]];</span><br><span class="line">    [_player setMedia:media];</span><br><span class="line">    [_player play];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#pragma mark - user interface</span><br><span class="line">// 方向控制，4个按钮分别对应0-3</span><br><span class="line">- (IBAction)directionButtonAction:(UIButton *)sender &#123;</span><br><span class="line">    ONVIF_PTZRelativeMove(_device, sender.tag);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (IBAction)switchUriStream:(UIButton *)sender &#123;</span><br><span class="line">    sender.selected = !sender.selected;</span><br><span class="line">    [self queryStreamURI];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="http://cyrus_huang.gitee.io/blog/2020/01/16/iOS-集成ONVIF客户端/onvif_oc_5.png" alt=""><br><img src="http://cyrus_huang.gitee.io/blog/2020/01/16/iOS-集成ONVIF客户端/onvif_oc_6.png" alt=""></p>


                
            </div>

            <!-- Comments -->
            
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    


                </div>
            
        </div>
    </div>
</article>

    <!-- Footer -->
    <hr>

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                    

                    

                    
                        <li>
                            <a href="https://github.com/klugjo/hexo-theme-clean-blog" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    

                    

                    
                </ul>
                <p class="copyright text-muted">&copy; 2020 Cyrus<br></p>
                <p class="copyright text-muted">Original Theme <a target="_blank" href="http://startbootstrap.com/template-overviews/clean-blog/">Clean Blog</a> from <a href="http://startbootstrap.com/" target="_blank">Start Bootstrap</a></p>
                <p class="copyright text-muted">Adapted for <a target="_blank" href="https://hexo.io/">Hexo</a> by <a href="http://www.codeblocq.com/" target="_blank">Jonathan Klughertz</a></p>
                <p class="copyright text-muted"><a href="http://www.beian.miit.gov.cn">粤ICP备18110122号-1</a></p>
            </div>
        </div>
    </div>
</footer>


    <!-- After footer scripts -->
    
<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Bootstrap -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Disqus Comments -->



</body>

</html>